import os

from agent.common.system import sysCommand
from agent.feature.base import Feature


class Hashsize(Feature):
    __domain__  = "net"
    __feature__ = "nf_conntrack_hashsize"
    
    def __init__(self) -> None:
        super().__init__(self.__domain__, self.__feature__)
        
        self.hashsize_path = "/sys/module/nf_conntrack/parameters/hashsize"
        if not os.path.exists(self.hashsize_path):
            raise Exception("file {} don't exists.".format(self.hashsize_path))
    
    def set_value(self, value):
        sysCommand("echo {} > {}".format(value, self.hashsize_path))
    
    def get_value(self):
        return sysCommand("cat {}".format(self.hashsize_path))